import { defineStore } from 'pinia'
import axios from 'axios';
import { nanoid } from "nanoid";
import { reactive } from 'vue'

export const useLoverStore = defineStore('lover', () => {
    const talkList = reactive(
        JSON.parse(localStorage.getItem('talkList') as string) || []
    )

    async function anotherOne() {
        let result = await axios.get(
            "https://api.uomg.com/api/rand.qinghua?format=json"
        );
        console.log(result.data);
        //talkList.push(result.data.content);  这句话之所以没用是因为没有 id, talkList 遍历不出来
        let obj = { id: nanoid(), sentence: result.data.content };
        console.log(obj);
        talkList.push(obj)
    }

    return { talkList, anotherOne }
})
